package standalone;

import java.io.File;

public class SchedulerService implements Runnable {

	static Thread serviceThread;
	private String[] args;
	
	private SchedulerService(String[] args) {
		this.args = args;
	}
	
	@Override
	public void run() {
		System.out.println("Running the service");
		Main.main(args);
	}

	public static void start(String[] args) {
		System.out.println("Starting the service");
		serviceThread = new Thread(new SchedulerService(args));
		serviceThread.start();		
	}

	public static void stop(String[] args) {
		System.out.println("Stopping the service");
	//	Main.stop(args);
		
	}
	
	public static void main(String[] args) {
		System.out.println("Starting service...");
		File f = new File("src/main/resources/META-INF/log4j.xml");
		if (f.exists()) {
		} else {
			f = new File("../META-INF/log4j.xml");
		}
		System.out.println("log4j from :  file:/"+f.getAbsolutePath().replace("\\", "/"));
		System.setProperty("log4j.configuration", "file:/"+f.getAbsolutePath().replace("\\", "/"));			
		System.setProperty("log4j.debug","true");
		File workingdir = f.getParentFile().getParentFile();
		String workDir = workingdir.getAbsolutePath().replace("\\", "/");
		String logDir = workingdir.getParentFile().getParentFile().getAbsolutePath().replace("\\", "/") + "/../bin";
		System.out.println("workDir: " + workDir +", logdir: " + logDir);
		System.setProperty("log4j.path", logDir);
		System.setProperty("user.dir", workDir);
		SchedulerService.start(args);
	}
}
